**Yeon Kyung Park 
**Replication do-file for ``Rethinking Multilateralism: Domestic Incentives of Multilateral Aid"
**Aug 2022

*create ideology variable
use cmp2021.dta,clear
format edate %d
gen month=month(edate)
gen year=year(edate)
orde	r month year
*use variables related to econonomically L-R ideology 
destring per401-per416, replace force
* use pcf since I am using many many variables and am trying to reduce it to one measurement of ideology
factor per401-per416, pcf 
* factor 1 to 6 have eigenvalues > 1. Thus, keep 6.
factor per401-per416, pcf factors(6)
rotate
predict factorA

*vanilla method:
*destring per101-per706,replace force
*factor per101-per706, pcf * eigenvalue>0  up to factor20
*factor per101-per706, pcf factors(20)
*rescale to 0 - 10 scale
sum factorA
gen factorA2 = (factorA - r(min)) / (r(max) - r(min)) * 10

*calculate L-R based on voteshare
destring pervote, replace force
gen pervotedec = pervote/100
*calculate L-R based on seats occupied in assembly
destring absseat totseat, replace force

bys country year month: gen perseat=absseat/totseat
gen partisan1=factorA2*pervotedec
gen partisan2=factorA2*perseat

* sum it by country-year
bysort country year: egen partisansum=total(partisan1)
bysort country year: egen partisanseatsum=total(partisan2)


* rile
sum rile
*rescale
gen rile2 = (rile - r(min)) / (r(max) - r(min)) * 10
gen rilev=rile2*pervotedec
gen riles=rile2*perseat
bys country year month: egen rilevsum=total(rilev)
bys country year month: egen rileseatsum=total(riles)
collapse (mean) partisansum partisanseatsum rilevsum rileseatsum, by(country countryname year month)
duplicates report
sort country year
quietly by country year: gen dup = cond(_N==1,0,_n)
tab dup
list countryname if dup>0
drop dup

tsset year
xtset year country
xtset country year
tsfill

*fill in nonelection years
bys country year: replace partisansum=partisansum[_n-1] if missing(partisansum)
drop dup
by country year: gen election=1 if !missing(partisansum)
by country year: replace election=0 if missing(partisansum)
by country year: gen lag=partisansum[_n-1]

bys country year: replace partisansum=partisansum[_n-1] if election==0 & !missing(partisansum[_n-1])
xtset country year
	replace partisansum=partisansum[_n-1] if partisansum==.
	replace partisanseatsum=partisanseatsum[_n-1] if partisanseatsum==.
	replace rilevsum=rilevsum[_n-1] if rilevsum==.
	replace rileseatsum=rileseatsum[_n-1] if rileseatsum==.

rename partisansum ideology1
rename partisanseatsum ideologyseat1
rename rilevsum ideology2
rename rileseatsum ideologyseat2


kountry countryname, from(other) stuck
rename _ISO3N_ iso3n
replace iso3n=iso3n[_n-1] if iso3n==.
drop if missing(iso3n)
drop if ideology1==0|ideologyseat1==0|ideology2==0|ideologyseat2==0
drop if year<1960
*then merge with execrlc from cmp data; milexp, gdpgrowth, openness from world bank wdi, socialexp from OECD, polchange from CHISOLS
*saved as "whymultilateralaid.dta"

**************Analysis
use whymultilateralaid.dta, clear
xtset iso3n year
eststo: quietly xtpcse multicomt ideology1 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideology1 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideology1 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideology1 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)

eststo: quietly xtpcse multicomt ideologyseat1 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideologyseat1 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideologyseat1 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideologyseat1 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
esttab using aidmainreal.tex, label title(Donor Governments' Economic Ideology and Foreign Aid Outflow)
estimates clear

*RILE ideology for online appendix
eststo: quietly xtpcse multicomt ideology2 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideology2 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideology2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideology2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)

eststo: quietly xtpcse multicomt ideologyseat2 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideologyseat2 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideologyseat2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideologyseat2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
esttab using aidmainiv4.tex, label title(Donor Governments' Economic Ideology and Foreign Aid Outflow)
estimates clear

*ADL*
eststo: quietly xtpcse multicomt l.multicomt ideology1 l.ideology1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt l.bicomt ideology1 l.ideology1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt l.multicomt ideology1 l.ideology1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt l.bicomt ideology1 l.ideology1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)

eststo: quietly xtpcse multicomt l.multicomt ideologyseat1 l.ideologyseat1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt l.bicomt ideologyseat1 l.ideologyseat1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt l.multicomt ideologyseat1 l.ideologyseat1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt l.bicomt ideologyseat1 l.ideologyseat1 openness l.openness gdpgrowth l.gdpgrowth milexp l.milexp polchange l.polchange coldwar l.coldwar polity l.polity socialexp l.socialexp, pairwise corr(psar1)
esttab using adlmain.tex, label title(Donor Governments' Economic Ideology and Foreign Aid Outflow (ADL))
estimates clear

eststo: quietly xtpcse multicomt ideology2 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideology2 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideology2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideology2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)

eststo: quietly xtpcse multicomt ideologyseat2 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bicomt ideologyseat2 l.bicomt openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse multidisbgr l.multidisbgr multicomt ideologyseat2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
eststo: quietly xtpcse bidisbgr l.bidisbgr bicomt ideologyseat2 openness gdpgrowth milexp polchange coldwar polity socialexp, pairwise corr(psar1)
esttab using adlalt.tex, label title(Donor Governments' Economic Ideology and Foreign Aid Outflow)
estimates clear


*ADL
* Stationarity 
xtunitroot fisher bicomt, dfuller drift lags(1) 
xtunitroot fisher bicomt, dfuller drift lags(1) demean
xtunitroot fisher multicomt, dfuller drift lags(1) 
xtunitroot fisher multicomt, dfuller drift lags(1) demean
xtunitroot fisher bidisbgr, dfuller drift lags(1) 
xtunitroot fisher bidisbgr, dfuller drift lags(1) demean
xtunitroot fisher multidsbgr, dfuller drift lags(1) 
xtunitroot fisher multidisbgr, dfuller drift lags(1) demean

*lag length determined based on AIC - ran varsoc for each iso3n and the average # of lags was 1.
*alternatively, ran levin-lin-chu test after balancing the panel to determine which lag to use. # of lag still 1. 

*use whymultilateralbalanced, clear
*xtunitroot llc bicomt, lags(aic) kernel(bartlett nw)
*xtunitroot llc bicomt, lags(aic) kernel(bartlett nw) demean
*xtunitroot llc multicomt, lags(aic) kernel(bartlett nw) 
*xtunitroot llc multicomt, lags(aic) kernel(bartlett nw) demean
*xtunitroot llc bidisbgr, lags(aic) kernel(bartlett nw)
*xtunitroot llc bidisbgr, lags(aic) kernel(bartlett nw) demean
*xtunitroot llc multidsbgr, lags(aic) kernel(bartlett nw)
*xtunitroot llc multidisbgr, lags(aic) kernel(bartlett nw) demean



*wooldrige test: xtserial multicomt ideology1 lmulticomt openness gdpgrowth milexp polchange coldwar polity socialexp
** LM (alternative to BG since BG cant be done on multiple panels)
*reg bidisbgr l.bidisbgr bicomt l.bicomt ideology1 l.ideology1 openness gdpgrowth milexp polchange coldwar polity socialexp l.openness l.gdpgrowth l.milexp l.polchange l.coldwar l.polity l.socialexp

*predict res, r
*gen resl=res[_n-1]
*replace resl=0 if resl==. 
*replace res=0 if res==.

*reg res resl l.bidisbgr bicomt l.bicomt ideology1 l.ideology1 openness gdpgrowth milexp polchange coldwar polity socialexp l.openness l.gdpgrowth l.milexp l.polchange l.coldwar l.polity l.socialexp

*heteoskedasticity (Breusch-Pagan (Lagrange Multiplier) Test}
reg multicomt ideology1 l.multicomt openness gdpgrowth milexp polchange coldwar polity socialexp
rvfplot
estat hettest

*for graph
graph bar bicomt bidisbgr, text(3350 510 "3,273 million") text(2580 2480 "2,504 million") legend(label(1 Commitment) label(2 Disbursement)) bar(1, color(gs8)) bar(2, color(gs2))
graph bar multicomt multidisbgr, text(1220 510 "1,094 million") text(890 1760 "812 million") legend(label(1 Commitment) label(2 Disbursement)) yscale(range(0 4000)) bar(1, color(gs8)) bar(2, color(gs2))

keep multicomt bicomt multidisbgr bidisbgr multidisbnet bidisbnet year iso3n
collapse (sum) multicomt bicomt multidisbgr bidisbgr, by(year)
twoway bar bicomt multicomt year, color(gs8 gs2) xscale(range(1970,2021))
twoway bar bidisbgr multidisbgr year, color(gs8 gs2) xscale(range(1970,2021))

